﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using UI.ParentForm;
using UI.Lib;
using UI.Lib.Factory;
using Components;
using Com.Seezt.Skins;

namespace UI.BaseResource
{
    public partial class FrmPsn0a00Setting : BaseEdit
    {
        public FrmPsn0a00Setting(string action, string text, string key, string comname)
            : base(action)
        {
            InitializeComponent();

            this.Text = text;
            this.key = key;
            //回写的方法
            this.SaveCallFuntion = "Psn0a00Manager$SaveData"; //保存的方法

            LoadData();

            this.tbSummary.SetValue("comcode", key);
            this.tbSummary.SetValue("comname", comname);

            this.Size = base.MidWindow;
        }


        protected override void AfterSystemChangeControlState()
        {
            this.tbSummary.Enable("comcode", Context.IsSuperUser);
        }

        protected void LoadData()
        {
            DataTable dt = CommonHelper.Entity.ExecFun("comsetting", new KeyValuePair<string, object>("comcode", key));

            if (null == dt || 0 == dt.Rows.Count) return;

            string name = string.Empty;
            foreach (DataRow dr in dt.Rows)
            {
                name = Validation.ToString(dr["name"]);

                this.tbSummary.SetValue(name, dr["value"]);
            }

            this.tbSummary.SaveBak();
        }

        public override bool BeforePopWin(string name, ref string where, ref string[] others)
        {
            if ("comcode" == name)
            {
                if (MsgBox.Show(this, "提示", "是否确定更换设置公司?", MessageBoxButtons.YesNo)
                    == DialogResult.No)
                {
                    return false;
                }
            }

            return true;
        }

        public override void AfterPopWin(string name, System.Collections.Hashtable data, bool ischange)
        {
            if ("comcode" == name && ischange)
            {
                this.key = Validation.ToString(this.tbSummary.GetValue("comcode"));
                LoadData();
            }
        }
    }
}
